<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>元素的层级</title>
    <style>
         /* 
                对于开启了定位元素(只有开启定位才能设置层级)，可以通过z-index属性来指定元素的层级
                    z-index需要一个整数作为参数，值越大元素的层级越高
                        元素的层级越高越优先显示

                    如果元素的层级一样，则优先显示靠下的元素

                    祖先的元素的层级再高也不会盖住后代元素
             */


        * {
            padding: 0;
            margin: 0;
        }

        .box {
            width: 500px;
            height: 300px;
            
            background-color: skyblue;
            position: relative;
            overflow: hidden;
        }

        .box1 {
            width: 200px;
            height: 200px;
            background-color: slateblue;
            position: absolute;
            top:30px;
            left: 100px;
            z-index: 4;
        }

        .box2 {
            width: 200px;
            height: 200px;
            background-color: tan;
            position: absolute;
            z-index: 10;
            top:50px;

        }
       
    
        
    
        
    </style>
</head>

<body>
    <div class="box ">
        <div class="box1"></div>
        <div class="box2"></div>
    </div>
</body>

</html>